<?php

namespace app\logic;

class Passport
{
    private $obj_model_name;
    private $str_model_name;
    private $str_id_name;

    public function __construct($str_model_name)
    {
        $this->str_model_name = $str_model_name;
        switch ($str_model_name) {
            case 'admin': // cms
                $this->obj_model_name = \app\model\AdminPassport::getInstance();
                $this->str_id_name = 'admin_id';
                break;
            case 'user': // 用户端
                $this->obj_model_name = \app\model\UserPassport::getInstance();
                $this->str_id_name = 'user_id';
                break;
            case 'enterprise': // 企业端
                $this->obj_model_name = \app\model\EnterprisePassport::getInstance();
                $this->str_id_name = 'enterprise_id';
                break;
            default:
                return false;
        }
    }

    /**
     * 验证passport 返回登录的编号
     * @return int
     */
    public function _checkPassport($str_passport, $str_platfrom)
    {
        _toValidate('passport', $str_passport, 10015);

        $int_id = $this->obj_model_name->getId($str_passport, $str_platfrom, $this->str_id_name);

        _toValidate('id', $int_id, 10015);

        return $int_id;
    }

    /**
     * 获取最新的登录票据
     * @param int $int_id 用户编号
     * @param string $str_platform 来自平台 web-网页 app-移动端 api-接口 wechat-微信端
     * @param string $int_id_name 相关的键值
     * @param bool $bool_is_add 是否添加新的passport
     * @return string
     */
    public function getPassport($int_id, $str_platform, $int_id_name, $bool_is_add)
    {
        return $this->obj_model_name->getPassport($int_id, $str_platform, $int_id_name, $bool_is_add);
    }
}
